package com.ocr.view;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

public class Box {

	static float DEFAULT_WIDTH = 20;
	static float DEFAULT_HEIGHT = 20;
	float x = 0;
	float y = 0;

	float width = DEFAULT_WIDTH;
	float height = DEFAULT_WIDTH;

	public Box(float x, float y) {
		this.x = x;
		this.y = y;
	}

	public boolean isTouchMe(float xtouch, float ytouch) {
		if (x - 5 < xtouch && xtouch < x + width + 5 && y - 5 < ytouch
				&& ytouch < y + height + 5) {
			return true;
		}
		return false;
	}

	public void moveTo(float xstep, float ystep) {
		x += xstep;
		y += ystep;
	}

	public float getTop() {
		return y;
	}

	public float getRight() {
		return x + width;
	}

	public float getBottom() {
		return y + height;
	}

	public float getLeft() {
		return x;
	}

	public float getDistance(float xpos, float ypos) {
		return (float) Math.sqrt(Math.pow(xpos - x, 2) + Math.pow(ypos - y, 2));
	}

	public void draw(Canvas canvas) {
		Paint paint = new Paint();
		paint.setColor(Color.RED);
		Rect rect = new Rect((int) x, (int) y, (int) (x + width),
				(int) (y + height));
		canvas.drawRect(rect, paint);
	}
}
